<template>
    <div class="app-container">
      
      <div style="border-top: 1px solid #333; margin: 20px 0;"></div>

      <!-- 登录容器 -->
      <div class="login-container">
        <div class="carousel-wrapper" v-if="wei">
          <el-carousel :interval="3000" height="600px" >
            <el-carousel-item v-for="(item, index) in items" :key="index"  @click="jumpw()">
              <img :src="item" class="carousel-image" />
            </el-carousel-item>
          </el-carousel>
        </div>

        <div class="login-card" v-else>
          <h2 class="login-title">用户登录</h2>
          <form>
            <div class="input-group">
              <label for="username">手机号</label>
              <input type="text" v-model="username" placeholder="请输入用户名" />
            </div>
            <div class="input-group">
              <label for="password">密码</label>
              <input type="password" v-model="password" placeholder="请输入密码" />
            </div>
            <el-radio-group v-model="selectedGender">
              <el-radio label="1">患者</el-radio>
              <el-radio label="2">医生</el-radio>
              <el-radio label="3">药师</el-radio>
              <el-radio label="4">管理</el-radio>
            </el-radio-group>
            <button class="login-button" @click="clock()">登录</button>
            <button  class="login-button" @click="register()">注册</button>
          </form>
        </div>
        
      </div>
      <div style="background-color: rgb(39,39,39);height: 250px;">
                <el-container>
                    <el-aside  style="margin-left: 40px;">
                        <p style="font-size: 16px; font-weight: bolder;color: #eee;">关于我们</p>
                        <p style="font-size: 12px;color: rgb(149, 149, 149);">医院概况  联系我们</p>
                        <p style="font-size: 12px;color: rgb(149, 149, 149);">常见问题  意见反馈</p>
                        <p style="font-size: 12px;color: rgb(149, 149, 149);">法律条款  关于我们</p>
                        <p style="font-size: 16px; font-weight: bolder;color: #eee;">关注我们</p>
                        <p style="font-size: 12px;color: rgb(149, 149, 149);">qq群:2824444900</p>
                        <!-- <p style="font-size: 12px;color: rgb(149, 149, 149);">qq群:2824444900</p> -->
                    </el-aside>
                    <el-main style="margin-left: 10px;">
                    <div  style="font-style: italic;font-size: 27px;color:rgb(255,255,255);font-weight: bolder !important;margin-left: 130px;margin-top: 20px;">医院预约管理系统</div>
                    <div style="font-size: 12px; color: rgb(149, 149, 149); font-weight: bolder; margin-left: 130px; margin-top: 10px;">由高教社联手网易推出，让每一个有提升愿望的用户能够学到中国知名高校的课程，并获得认证。</div>
                    <div style="font-size: 12px; color: rgb(149, 149, 149); margin-left: 130px; margin-top: 10px;">
                        网上有害信息举报（涉未成年人）：网站  邮箱（涉未成年人） youdao_jubao@rd.netease.com
                    </div>
                    <div style="font-size: 12px; color: rgb(149, 149, 149); margin-left: 130px; margin-top: 5px;">
                        粤B2-20090191-26 | 京ICP备12020869号-2 | 京公网安备44010602000207
                    </div>
                </el-main>
                </el-container>
            
          </div>
    </div>
  </template>
  
  <script setup lang="ts">
  import { ref } from 'vue';
  import {useRoute,useRouter} from 'vue-router'
  import axios from 'axios';
  import { login } from "@/api/userApi";
  import type { UserLoginRequest } from "@/type/user";
  
  const selectedGender = ref("1"); // 默认选项
  const username = ref("");
  const password = ref("");
  const router = useRouter();
  const items = [
    "src/Login/image_login/image1.png",
    "src/Login/image_login/image2.jpg",
    "src/Login/image_login/image3.jpg",
    "src/Login/image_login/image4.jpg",
  ];
  let wei = ref(true);
  
  const user = ref<UserLoginRequest>({
    
  userId: 0,
  userType: 0,
  userPhone: "",
  password: "",
  userEmail: "",
  avatar: "",
  isDelete: 0

  })
  let user2 = {
    phone:"",
    code:"",
    password:""
  }
  const clock =  () => {
    if(username.value==""||password.value==""||selectedGender.value==""){
      alert("请完善登入信息！");
    }else{
      console.log("密码格式正确")
      const phoneRegex = /^(?:\+?86)?1[3-9]\d{9}$/;
      const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
      user.value.password=password.value;//用户密码
      user.value.userType=Number(selectedGender.value);
      if (phoneRegex.test(username.value)) {
        user.value.userPhone=username.value;
      } else if (emailRegex.test(username.value)) {
       
        user.value.userEmail=username.value;
      }

      
      user2.phone=username.value;
      user2.code="7902";
      user2.password=password.value;
      console.log(user2);
      if(selectedGender.value=="1"){
        axios.post("http://zhsj.autumnclouds.cn/patient/login", user2)
            .then((response) => {       
              console.log(response.data.data);
              localStorage.setItem('sys', '2');
              localStorage.setItem('username1', response.data.data.token);
              localStorage.setItem('username2', response.data.data.id);
              localStorage.setItem('username3', response.data.data.name);
              alert("登陆成功!");
            })
            .catch((error) => {
              alert("密码错误!");
            });
      }else if(selectedGender.value=="2"){
        axios.post("http://zhsj.autumnclouds.cn/doctor/login", user2)
            .then((response) => {

              console.log(response.data);
              localStorage.setItem('sys', '1');
              localStorage.setItem('username1', response.data.data.token);
              localStorage.setItem('username2', response.data.data.id);
              localStorage.setItem('username3', response.data.data.name);
              alert("登陆成功!");
            })
            .catch((error) => {
              alert("密码错误!");
            });
      }else if(selectedGender.value=="3"){
        axios.post("http://zhsj.autumnclouds.cn/patient/login", user2)
            .then((response) => {       
              console.log(response);
            })
            .catch((error) => {
              alert("该用户已经存在!");
            });
      }
      
      router.push("/manager")
    
    }
  
  };

  const register = () => {
    router.push("/register")
  
  };
  const jumpw = () => {
    wei.value=!wei.value;
    console.log(wei);
  };
  </script>
  
  <style scoped>
  .app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }
  
 
  
  /* 登录容器 */
  .login-container {
    display: flex;
    justify-content: center;
    align-items: top;
    height: 750px;
    background: linear-gradient(135deg, hsl(130, 230, 230), #acb6e5);
  }
  
  /* 登录卡片 */
  .login-card {
    width: 450px;
    height:450px;
    margin-top: 70px;
    background: #fff;
    padding: 40px 30px;
    border-radius: 10px;
    box-shadow: 0px 15px 25px rgba(0, 0, 0, 0.2); /* 阴影立体感 */
    transform: translateY(0); /* 初始位置 */
    transition: transform 0.3s ease, box-shadow 0.3s ease; /* 平滑动画 */
  }
  
  .login-card:hover {
    transform: translateY(-10px); /* 上移效果 */
    box-shadow: 0px 25px 35px rgba(0, 0, 0, 0.3); /* 更明显阴影 */
  }
  
  /* 标题 */
  .login-title {
    font-size: 24px;
    color: #333;
    text-align: center;
    margin-bottom: 20px;
  }
  
  /* 表单输入组 */
  .input-group {
    margin-bottom: 15px;
    margin-right: 15px;
  }
  
  .input-group label {
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
    display: block;
  }
  
  .input-group input {
    width: 100%;
    padding: 10px 15px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 5px;
    transition: border-color 0.3s ease;
  }
  
  .input-group input:focus {
    outline: none;
    border-color: #74ebd5; /* 焦点颜色 */
  }
  
  /* 登录按钮 */
  .login-button {
    margin-top: 20px;
    display: block;
    width: 100%;
    padding: 10px 15px;
    font-size: 16px;
    color: #fff;
    background: linear-gradient(135deg, #ad62d2, #acb6e5);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }
  
  .login-button:hover {
    transform: scale(1.05); /* 放大效果 */
    box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.2);
  }
  
  /* 轮播图 */
  .carousel-wrapper {
    margin-top: 70px;
    width: 100%;
    height: 100%;
    margin-right: 100px;
    margin-left: 100px;
  }
  
  .carousel-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  </style>